# coding: utf-8
from sqlalchemy import Column, DateTime, ForeignKey, String, Text, text
from sqlalchemy.dialects.mysql import INTEGER, LONGTEXT, SMALLINT, TINYINT, VARCHAR
from sqlalchemy.orm import relationship

from api.core.base_db import Base


class ZhanWechatVideoContent(Base):
    __tablename__ = 'zhan_wechat_video_content'
    __table_args__ = {'comment': '发送信息内容'}

    id = Column(INTEGER(11), primary_key=True)
    sender_id = Column(INTEGER(11), nullable=False, comment='创建者ID\\n')
    text = Column(LONGTEXT, comment='发送的内容&聊天框信息')
    is_delete = Column(SMALLINT(2), server_default=0, comment='是否删除（默认0）')
    create_time = Column(DateTime, comment='创建时间')
    update_time = Column(DateTime, comment='修改时间')
    group_id = Column(INTEGER(11), nullable=False, comment='人物分组ID')


class ZhanWechatVideoGroup(Base):
    __tablename__ = 'zhan_wechat_video_group'
    __table_args__ = {'comment': '分组'}

    id = Column(INTEGER(11), primary_key=True, comment='id')
    group_name = Column(String(255), nullable=False, comment='分组名称')
    sort = Column(INTEGER(11), nullable=False, comment='排序')
    is_delete = Column(SMALLINT(2), server_default=text("'0'"), comment='是否删除')
    create_time = Column(DateTime, comment='创建时间')
    update_time = Column(DateTime, comment='修改时间')
    use_id = Column(INTEGER(11), nullable=False, comment='用户id')


class ZhanWechatVideoPerson(Base):
    __tablename__ = 'zhan_wechat_video_person'
    __table_args__ = {'comment': '人物表'}

    id = Column(INTEGER(11), primary_key=True, comment='id')
    sender_name = Column(String(255), comment='发送者名字')
    sender_head = Column(String(255), comment='发送者头像')
    group_id = Column(ForeignKey('zhan_wechat_video_group.id', ondelete='SET NULL'), index=True, comment='分组id')
    create_time = Column(DateTime, comment='创建时间')
    update_time = Column(DateTime, comment='修改时间')
    create_by = Column(ForeignKey('zhan_user.id', ondelete='CASCADE'), index=True, comment='创建用户')

    zhan_user = relationship('ZhanUser')
    group = relationship('ZhanWechatVideoGroup')
